#ifndef _PWM_H_
#define _PWM_H_

#include "define.h"

#define	SysPWM_Frequency	32000000
#define d_PWM_F				35000//	//initialization PWM Freq 

#define	MIN_FRE				17300//17500//  minimum PWM frequency  17500
#define	MAX_FRE				50000	//maximum PWM frequency					

#define DEAD0_TIME			2000 	/* PWM0 Dead Time set ns */
#define DEAD1_TIME			2000 	/* PWM1 Dead Time set ns */
#define DEAD0_1_TIME		1500//2000 	/* PWM0 and PWM1 Dead Time set ns */
#define	DEAD0_1_Min_TIME	1000		/* Dead Time  MIN */ 

#define DEC_PWM_Period  	30//200	
#define	MIN_PHASE_WIDTH		500//1000//2000//3000	/* minimum phase width 3000ns */
#define	PHASE0				0		/* Select Phase 0 to detect */
#define	PHASE1				1		/* Select Phase 1 to detect */


#define PWM_ATMPC_En()		{ _atmpc=1;}
#define PWM_ATMPC_Dis()		{ _atmpc=0;}

#define PWM_MIN_En()		{ _pminpte=1;}
#define PWM_MIN_Dis()		{ _pminpte=0;}

#define PWM_OFF_En()		{ _pwmoffc=1;}
#define PWM_OFF_Dis()		{ _pwmoffc=0;}

#define PWM_PeriodMax_En()	{ _pmaxpte=1;}
#define PWM_PeriodMax_Dis()	{ _pmaxpte=0;}

#define PWM_MASK_ON()		{ _mss1=1;_mss0=1;}
#define PWM_MASK_OFF()		{ _mss1=0;_mss0=0;}

#define PWM_ON()			{ _pwmon=1;}
#define PWM_OFF()			{ _pwmon=0;}
#define DT_ON()				{ _dte=1;}
#define DT_OFF()			{ _dte=0;}


typedef enum
{
	DELAY_0_PWMP	= (unsigned char) 0x00,	/**< wait for 0 PWM clock */
	DELAY_1_PWMP	= (unsigned char) 0x10,	/**< wait for 1 PWM clock */
	DELAY_2_PWMP	= (unsigned char) 0x20,	/**< wait for 2 PWM clock */
	DELAY_3_PWMP	= (unsigned char) 0x30,	/**< wait for 3 PWM clock */
	DELAY_4_PWMP	= (unsigned char) 0x40,	/**< wait for 4 PWM clock */
	DELAY_5_PWMP	= (unsigned char) 0x50,	/**< wait for 5 PWM clock */
	DELAY_6_PWMP	= (unsigned char) 0x60,	/**< wait for 6 PWM clock */
	DELAY_7_PWMP	= (unsigned char) 0x70,	/**< wait for 7 PWM clock */	
}PHASE_DETECT_DELAY_TypeDef;


void PWM_Safe_protection_Init(unsigned int PWM_Limit_MAX_Fr,unsigned int PWM_Limit_MIN_Fr,unsigned char PWM_Auto_Adj_DECPWMP); 
void Phase_Protection_Init(unsigned char  PhaseSelect,unsigned char PWM_DelayPeriod,unsigned int Phase_Protect_sitatime_ns);
void DTS0_1_Setting(unsigned int DT0_1_time_ns);
void DTS_Setting(unsigned int DT0_time_ns,unsigned int DT1_time_ns);
void PWM_MASK_Init(unsigned char  MASK0_Data,unsigned char  MASK1_Data);
void PWM_Freq_Init(unsigned char PWM_Clock_DIV,unsigned int Init_Fre);
void IGBT_OFF(unsigned int PWM_Fr);
void IGBT_OFF1(unsigned int PWM_Fr);
void PWM_Update(unsigned int PWM_Fr);
void PWM_Update1(unsigned int PWM_Fr);
//void PWMMAX_Update(unsigned int PWM_Fr);
//void PWMMAX_Update1(unsigned int PWM_Fr);
void ClearMSS0_1(void);
void ClearMSS0_1_for_ISR(void);

#endif

/******************* End of  file ***************/